package com.vrv.common;

import android.content.Context;
import android.util.Log;

import com.vrv.common.config.EdpSharedPreferences;
import com.vrv.common.util.SharedPreferencesHelper;

/**
 * 服务器IP、port保存获取等
 * @author zxb
 */
public class UrlPrefix {
    private static final boolean DEBUG = true;
    private static final String TAG = UrlPrefix.class.getSimpleName();

    
	public Context mContext;
	public UrlPrefix(Context context){
		this.mContext = context;
	}
	
	public static Context sContext;
	public static void init(Context ctx){
		sContext = ctx;
	}
	
	/**协议头*/
	public static final String PREFIX = "http://";
	/**项目名*/
	public static final String PROJECT = "EDPDMServer";
	/**路径分隔符*/
	public static final String SPLIT_PORT = ":";
	public static final String SPLIT = "/";

	/**
	 * 获取服务器链接地址
	 * @return
	 */
	public String getUrlPrefix(){
		if (DEBUG) Log.v(TAG, "public String getUrlPrefix()");
		SharedPreferencesHelper sHelper = new SharedPreferencesHelper(mContext, EdpSharedPreferences.ServerSetting.SERVER_INFO_FILENAME);
		String ipValue = sHelper.getValue(EdpSharedPreferences.ServerSetting.SERVER_IP_KEY);
		String portValue = sHelper.getValue(EdpSharedPreferences.ServerSetting.SERVER_PORT_KEY);
		
		if (null == ipValue || null == portValue) {
			return null;
		}
		
		String url = PREFIX + ipValue + SPLIT_PORT + portValue + SPLIT + PROJECT;
		if (DEBUG) Log.v(TAG, url);
		return url;
	}
	
	public static String getUrlPrefix2(){
		if (DEBUG) Log.v(TAG, "public String getUrlPrefix2()");
		
		SharedPreferencesHelper sHelper = new SharedPreferencesHelper(sContext, EdpSharedPreferences.ServerSetting.SERVER_INFO_FILENAME);
		String ipValue = sHelper.getValue(EdpSharedPreferences.ServerSetting.SERVER_IP_KEY);
		String portValue = sHelper.getValue(EdpSharedPreferences.ServerSetting.SERVER_PORT_KEY);
		
		if (null == ipValue || null == portValue) {
			return null;
		}
		
		String url = PREFIX + ipValue + SPLIT_PORT + portValue + SPLIT + PROJECT;
		if (DEBUG) Log.v(TAG, url);
		return url;
	}
}
